package com.tl.khadmin.controller;
 
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tl.khadmin.bean.ProductType;
import com.tl.khadmin.bean.Supplier;
import com.tl.khadmin.bean.SupplierBankAccount;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.SupplierIService; 
import com.tl.khadmin.util.CommonUtil;

/**
 * 供应商控制器
 * @author 123
 */
@RestController
@RequestMapping(value = "/supplier")
public class SupplierController {
	
	@Resource
	private SupplierIService supplierService; 
	
	/**
	 * @param param level：查询商品品牌列表
	 * @param param brandName：名称，模糊查询
	 * @param param status：1启用，2禁用
	 * @return
	 */
	@RequestMapping(value="/list") 
	public Map<String, List<Supplier>> listSupplier(@RequestParam Map<String ,Object> param){
		return CommonUtil.returnResultCodeJson("productType", supplierService.listSupplier(param));
	}

	@RequestMapping(value = "/showbypage")
	public Map<String, Page<Supplier>> showSupplierByPage(HttpSession session, @RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		return CommonUtil.returnResultCodeJson("result", supplierService.showSupplierByPage(session, pageNum, pageSize, params));
	}
	
	/**
	 * 供应商银行账号
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "/bankaccount/page")
	public Map<String, Page<SupplierBankAccount>> showBankaccountByPage(HttpSession session, @RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		return CommonUtil.returnResultCodeJson("result", supplierService.showBankaccountByPage(session, pageNum, pageSize, params));
	}
	
	/**
	 * 供应商银行账号审核
	 * @param session
	 * @param supplier
	 * @return
	 */
	@RequestMapping(value = "/bankaccount/audit") 
	@ResponseBody
	public String auditSupplierBankAccount(HttpSession session, SupplierBankAccount bankAccount) {
		return supplierService.auditSupplierBankAccount(session, bankAccount);
	} 
	
	
	@RequestMapping(value = "/audit") 
	@ResponseBody
	public String auditSupplier(HttpSession session, Supplier supplier) {
		return supplierService.auditSupplier(session, supplier);
	} 
	
	@RequestMapping(value = "/update") 
	@ResponseBody
	public String updateSupplier(HttpSession session, Supplier supplier) {
		return supplierService.updateSupplier(session, supplier);
	} 
	
	@RequestMapping(value = "/delete") 
	@ResponseBody
	public String deleteSupplier(Supplier supplier) {
		return supplierService.deleteSupplier(supplier);
	} 
	
	@RequestMapping(value = "/status") 
	@ResponseBody
	public String updateSupplierStatus(Supplier supplier) {
		return supplierService.updateSupplierStatus(supplier);
	} 

	@RequestMapping(value = "/deletebyids")
	@ResponseBody
	public String deleteByIds(String ids) {
		if(StringUtils.isBlank(ids)){
			return CommonUtil.returnMapResultByRows(0, "","未勾选");
		}
		return supplierService.deleteByIds(ids);
	}

	@RequestMapping(value = "/querybyid")
	@ResponseBody
	public Map<String, Object> querySupplierById(Long id) {
		if(id==null){
			return null;
		}
		return supplierService.querySupplierById(id);
	}
	
}
